from django.db import models
from django.db.models import permalink

from s_te.managers import PublishedManager
import capabilities.models
import tagging

class CommentEngine(models.Model):
    """
    The comment engine to use
    """
    comment_engine = models.CharField(max_length=100, unique=True)
    
    class Meta:
        ordering = ['comment_engine']
    def __unicode__(self):
        return self.comment_engine

class Category(models.Model):
    """
    The category of the blog entry
    """
    category = models.CharField(max_length=100, unique=True)
    slug = models.SlugField(unique=True)
    order = capabilities.models.OrderField()
    feedburner_url = models.URLField(blank=True)
    
    class Meta:
        ordering = ['order']
    def __unicode__(self):
        return self.category
    
    @permalink
    def get_absolute_url(self):
        return ('bl_g_category', [str(self.slug)])
    
class Entry(models.Model):
    """
    An entry in the blog
    """
    author = capabilities.models.UserField()
    title = models.CharField(max_length=100)
    slug = models.SlugField(unique=True)
    summary = models.TextField()
    body = models.TextField()
    published = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    allow_comments = models.BooleanField(default=True)
    comments_closed = models.BooleanField(default=False)
    archive = models.BooleanField(default=False)
    comment_engine = models.ForeignKey(CommentEngine)
    call_to_action = models.BooleanField(default=True)
    draft = models.BooleanField(default=False)
    category = models.ForeignKey(Category)
    
    objects = models.Manager()
    published_objects = PublishedManager() 
    
    class Meta:
        ordering = ['title']
        
    @permalink
    def get_absolute_url(self):
        return ('bl_g_entry', [str(self.slug)])

tagging.register(Entry)